<!-- HTML header for doxygen 1.8.3.1-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.3.1"/>
<title>AngelScript: grid template object</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<script type="test/javascript" src="touch.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
  $(window).load(resizeHeight);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td id="projectlogo"><img alt="Logo" src="aslogo_small.png"/></td>
  <td style="padding-left: 0.5em;">
   <div id="projectname">AngelScript
   </div>
  </td>
   <td>        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
</td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.3.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
      <div id="nav-sync" class="sync"></div>
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
$(document).ready(function(){initNavTree('doc_addon_grid.html','');});
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Macros</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div class="header">
  <div class="headertitle">
<div class="title">grid template object </div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><b>Path:</b> /sdk/add_on/scriptgrid/</p>
<p>The <code>grid</code> type is a <a class="el" href="doc_adv_template.html">template object</a> that allow the scripts to declare 2D grids of any type. In many ways it is similar to the <a class="el" href="doc_addon_array.html">array template object</a>, but it is specialized for use with areas.</p>
<p>The type is registered with <code>RegisterScriptGrid(asIScriptEngine *engine)</code>.</p>
<h1><a class="anchor" id="doc_addon_grid_1"></a>
Public C++ interface</h1>
<div class="fragment"><div class="line"><span class="keyword">class </span>CScriptGrid</div>
<div class="line">{</div>
<div class="line"><span class="keyword">public</span>:</div>
<div class="line">  <span class="comment">// Set the memory functions that should be used by all CScriptGrids</span></div>
<div class="line">  <span class="keyword">static</span> <span class="keywordtype">void</span> SetMemoryFunctions(<a class="code" href="angelscript_8h.html#a9813f6b04d4879aefc203794fe04a5b0" title="The function signature for the custom memory allocation function.">asALLOCFUNC_t</a> allocFunc, <a class="code" href="angelscript_8h.html#a9dd42e5d8378d6a8aa8f35efacfb772e" title="The function signature for the custom memory deallocation function.">asFREEFUNC_t</a> freeFunc);</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Factory functions</span></div>
<div class="line">  <span class="keyword">static</span> CScriptGrid *Create(<a class="code" href="classas_i_type_info.html" title="The interface for describing types This interface is used to describe the types in the script engine...">asITypeInfo</a> *gridType);</div>
<div class="line">  <span class="keyword">static</span> CScriptGrid *Create(<a class="code" href="classas_i_type_info.html" title="The interface for describing types This interface is used to describe the types in the script engine...">asITypeInfo</a> *gridType, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815" title="32 bit unsigned integer">asUINT</a> width, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815" title="32 bit unsigned integer">asUINT</a> height);</div>
<div class="line">  <span class="keyword">static</span> CScriptGrid *Create(<a class="code" href="classas_i_type_info.html" title="The interface for describing types This interface is used to describe the types in the script engine...">asITypeInfo</a> *gridType, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815" title="32 bit unsigned integer">asUINT</a> width, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815" title="32 bit unsigned integer">asUINT</a> height, <span class="keywordtype">void</span> *defaultValue);</div>
<div class="line">  <span class="keyword">static</span> CScriptGrid *Create(<a class="code" href="classas_i_type_info.html" title="The interface for describing types This interface is used to describe the types in the script engine...">asITypeInfo</a> *gridType, <span class="keywordtype">void</span> *listBuffer);</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Memory management</span></div>
<div class="line">  <span class="keywordtype">void</span> AddRef() <span class="keyword">const</span>;</div>
<div class="line">  <span class="keywordtype">void</span> Release() <span class="keyword">const</span>;</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Type information</span></div>
<div class="line">  <a class="code" href="classas_i_type_info.html" title="The interface for describing types This interface is used to describe the types in the script engine...">asITypeInfo</a>   *GetGridObjectType() <span class="keyword">const</span>;</div>
<div class="line">  <span class="keywordtype">int</span>            GetGridTypeId() <span class="keyword">const</span>;</div>
<div class="line">  <span class="keywordtype">int</span>            GetElementTypeId() <span class="keyword">const</span>;</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Size</span></div>
<div class="line">  <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815" title="32 bit unsigned integer">asUINT</a> GetWidth() <span class="keyword">const</span>;</div>
<div class="line">  <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815" title="32 bit unsigned integer">asUINT</a> GetHeight() <span class="keyword">const</span>;</div>
<div class="line">  <span class="keywordtype">void</span>   Resize(<a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815" title="32 bit unsigned integer">asUINT</a> width, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815" title="32 bit unsigned integer">asUINT</a> height);</div>
<div class="line">  </div>
<div class="line">  <span class="comment">// Get a pointer to an element. Returns 0 if out of bounds</span></div>
<div class="line">  <span class="keywordtype">void</span>       *At(<a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815" title="32 bit unsigned integer">asUINT</a> x, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815" title="32 bit unsigned integer">asUINT</a> y);</div>
<div class="line">  <span class="keyword">const</span> <span class="keywordtype">void</span> *At(<a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815" title="32 bit unsigned integer">asUINT</a> x, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815" title="32 bit unsigned integer">asUINT</a> y) <span class="keyword">const</span>;</div>
<div class="line"></div>
<div class="line">  <span class="comment">// Set value of an element. </span></div>
<div class="line">  <span class="comment">// The value arg should be a pointer to the value that will be copied to the element.</span></div>
<div class="line">  <span class="comment">// Remember, if the grid holds handles the value parameter should be the </span></div>
<div class="line">  <span class="comment">// address of the handle. The refCount of the object will also be incremented</span></div>
<div class="line">  <span class="keywordtype">void</span>  SetValue(<a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815" title="32 bit unsigned integer">asUINT</a> x, <a class="code" href="angelscript_8h.html#ac8186f029686800b7ce36bde4a55c815" title="32 bit unsigned integer">asUINT</a> y, <span class="keywordtype">void</span> *value);</div>
<div class="line">};</div>
</div><!-- fragment --><h1><a class="anchor" id="doc_addon_grid_2"></a>
Public script interface</h1>
<pre>
  class grid&lt;T&gt;
  {
    grid();
    grid(uint width, uint height);
    grid(uint width, uint height, const T &amp;in fillValue);</pre><pre>    uint width() const;
    uint height() const;
    void resize(uint w, uint h);</pre><pre>    T &amp;opIndex(uint, uint);
    const T &amp;opIndex(uint, uint) const;
  }
</pre><p><b>grid()</b><br/>
 <b>grid(uint width, uint height)</b><br/>
 <b>grid(uint width, height, const T &amp;in fillValue)</b><br/>
</p>
<p>The constructors initializes the grid object. The default constructor will create an zero sized grid.</p>
<p><b>uint width() const</b><br/>
 <b>uint height() const</b><br/>
</p>
<p>Returns the width and height of the grid.</p>
<p><b>void resize(uint w, uint h)</b></p>
<p>Resizes the grid to the new dimension. The elements that still fit in the grid will keep their values.</p>
<p><b>T &amp;opIndex(uint x, uint y)</b><br/>
 <b>const T &amp;opIndex(uint x, uint y) const</b><br/>
</p>
<p>The index operator returns a reference to one of the elements. If the index is out of bounds a script exception will be raised.</p>
<h1><a class="anchor" id="doc_addon_grid_3"></a>
Example usage in script</h1>
<pre>
  // Initialize a 5x5 map
  grid&lt;int&gt; map = {{1,0,1,1,1},
                   {0,0,1,0,0},
                   {0,1,1,0,1},
                   {0,1,1,0,1},
                   {0,0,0,0,1}};</pre><pre>  // A function to verify if the next area is walkable
  bool canWalk(uint x, uint y)
  {
    // If the map in the destination is 
    // clear, it is possible to wark there
    return map[x,y] == 0;
  }
</pre> </div></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
  <ul>
    <li class="footer">Generated on Sun Dec 18 2016 12:35:27 for AngelScript by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.8.3.1 </li>
  </ul>
</div>
</body>
</html>
